// $ANTLR 3.1.2 AmFmCodeGenerator.g 2009-05-11 14:39:33

/*
 * Copyright 2009, Team Mondegreen:
 * Brian Hsieh - bh2181@columbia.edu
 * Eugene Yao - eyy2102@columbia.edu
 * Jake Amonette - jaa2149@columbia.edu
 * Tal Giat - tg2235@colubia.edu
 * 
 * This file is part of AMFM (A Minimal Fractal Music Language), a language created for
 * fractal music as part of the Programming Languages and Translator class at Columbia university.
 *
 * For more details go to: http://code.google.com/p/amfm/
 * 
 * AMFM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * at your option any later version.
 * 
 * AMFM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with AMFM.  If not, see <http://www.gnu.org/licenses/>. 
 */

package org.mondegreen.amfm.compiler;

import java.util.Map;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

import org.antlr.stringtemplate.*;
import org.antlr.stringtemplate.language.*;
import java.util.HashMap;
/**
 *
 * AST walker for AMFM AST that emits java code to generate music files from source AMFM code.
 * The java code uses modified version of Fractal Composer as the underlying library to help
 * with self similarity manipulations and midi/sound files generation.
 *
 * @author talgiat
 */
@SuppressWarnings("all")
public class AmFmCodeGenerator extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PROGRAM", "DEF", "NOTEUNIT", "NOTE", "ID", "INSTRUMENT", "REST", "FRACTION", "VOLUME_LEVELS_MINUS_F", "NOTELETTERS_WITH_ACCIDENTAL_MINUS_F", "ACCIDENTAL", "ONE_TO_NINE", "START", "PLAY", "SS_PITCH", "SS_VOLUME", "SS_RHYTHM", "SS_PITCH_VOLUME", "SS_PITCH_RHYTHM", "SS_RHYTHM_VOLUME", "SS_ALL", "BOOLEAN", "TEN_AND_UP", "COMMENT", "WS", "'seed'", "'{'", "';'", "'}'", "','", "'F'", "'('", "')'"
    };
    public static final int ONE_TO_NINE=15;
    public static final int SS_PITCH=18;
    public static final int SS_RHYTHM=20;
    public static final int T__29=29;
    public static final int DEF=5;
    public static final int REST=10;
    public static final int SS_ALL=24;
    public static final int ACCIDENTAL=14;
    public static final int SS_RHYTHM_VOLUME=23;
    public static final int SS_PITCH_VOLUME=21;
    public static final int ID=8;
    public static final int INSTRUMENT=9;
    public static final int EOF=-1;
    public static final int TEN_AND_UP=26;
    public static final int NOTELETTERS_WITH_ACCIDENTAL_MINUS_F=13;
    public static final int NOTEUNIT=6;
    public static final int SS_VOLUME=19;
    public static final int T__30=30;
    public static final int SS_PITCH_RHYTHM=22;
    public static final int T__31=31;
    public static final int T__32=32;
    public static final int T__33=33;
    public static final int BOOLEAN=25;
    public static final int WS=28;
    public static final int T__34=34;
    public static final int T__35=35;
    public static final int T__36=36;
    public static final int NOTE=7;
    public static final int START=16;
    public static final int PROGRAM=4;
    public static final int VOLUME_LEVELS_MINUS_F=12;
    public static final int FRACTION=11;
    public static final int COMMENT=27;
    public static final int PLAY=17;

    // delegates
    // delegators


        public AmFmCodeGenerator(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public AmFmCodeGenerator(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected StringTemplateGroup templateLib =
      new StringTemplateGroup("AmFmCodeGeneratorTemplates", AngleBracketTemplateLexer.class);

    public void setTemplateLib(StringTemplateGroup templateLib) {
      this.templateLib = templateLib;
    }
    public StringTemplateGroup getTemplateLib() {
      return templateLib;
    }
    /** allows convenient multi-value initialization:
     *  "new STAttrMap().put(...).put(...)"
     */
    public static class STAttrMap extends HashMap {
      public STAttrMap put(String attrName, Object value) {
        super.put(attrName, value);
        return this;
      }
      public STAttrMap put(String attrName, int value) {
        super.put(attrName, new Integer(value));
        return this;
      }
    }

    public String[] getTokenNames() { return AmFmCodeGenerator.tokenNames; }
    public String getGrammarFileName() { return "AmFmCodeGenerator.g"; }


    private static final int DEFAULT_OCTAVE = 4;
    private Map<String,String> instrumentsMap;

    public void setInstrumentsMap(Map<String,String> instrumentsMap) {
      this.instrumentsMap = instrumentsMap;
    }

    //private String buildWithComma(StringTemplate st


    public static class program_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "program"
    // AmFmCodeGenerator.g:58:1: program[String filePath,String progamName] : ^( PROGRAM (s+= seed )+ (stf= start_func ) ) -> amfm_class_tpl(file_path=filePathclass_name=progamNameseeds=$sstart_function=$stf.st);
    public final AmFmCodeGenerator.program_return program(String filePath, String progamName) throws RecognitionException {
        AmFmCodeGenerator.program_return retval = new AmFmCodeGenerator.program_return();
        retval.start = input.LT(1);

        List list_s=null;
        AmFmCodeGenerator.start_func_return stf = null;

        AmFmCodeGenerator.seed_return s = null;
         s = null;
        try {
            // AmFmCodeGenerator.g:58:43: ( ^( PROGRAM (s+= seed )+ (stf= start_func ) ) -> amfm_class_tpl(file_path=filePathclass_name=progamNameseeds=$sstart_function=$stf.st))
            // AmFmCodeGenerator.g:58:45: ^( PROGRAM (s+= seed )+ (stf= start_func ) )
            {
            match(input,PROGRAM,FOLLOW_PROGRAM_in_program46); 

            match(input, Token.DOWN, null); 
            // AmFmCodeGenerator.g:58:55: (s+= seed )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==ID) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // AmFmCodeGenerator.g:58:56: s+= seed
            	    {
            	    pushFollow(FOLLOW_seed_in_program51);
            	    s=seed();

            	    state._fsp--;

            	    if (list_s==null) list_s=new ArrayList();
            	    list_s.add(s.getTemplate());


            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);

            // AmFmCodeGenerator.g:58:66: (stf= start_func )
            // AmFmCodeGenerator.g:58:67: stf= start_func
            {
            pushFollow(FOLLOW_start_func_in_program58);
            stf=start_func();

            state._fsp--;


            }


            match(input, Token.UP, null); 


            // TEMPLATE REWRITE
            // 59:29: -> amfm_class_tpl(file_path=filePathclass_name=progamNameseeds=$sstart_function=$stf.st)
            {
                retval.st = templateLib.getInstanceOf("amfm_class_tpl",
              new STAttrMap().put("file_path", filePath).put("class_name", progamName).put("seeds", list_s).put("start_function", (stf!=null?stf.st:null)));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "program"

    public static class seed_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "seed"
    // AmFmCodeGenerator.g:62:1: seed : ^( ID INSTRUMENT (nu+= note_unit )+ ) -> seed_tpl(name=$ID.textnu=$nuinstrument=instrumentsMap != null && instrumentsMap.get($INSTRUMENT.text) != null ? instrumentsMap.get($INSTRUMENT.text) : \"NO_INSTRIMENT\");
    public final AmFmCodeGenerator.seed_return seed() throws RecognitionException {
        AmFmCodeGenerator.seed_return retval = new AmFmCodeGenerator.seed_return();
        retval.start = input.LT(1);

        CommonTree ID1=null;
        CommonTree INSTRUMENT2=null;
        List list_nu=null;
        AmFmCodeGenerator.note_unit_return nu = null;
         nu = null;
        try {
            // AmFmCodeGenerator.g:62:7: ( ^( ID INSTRUMENT (nu+= note_unit )+ ) -> seed_tpl(name=$ID.textnu=$nuinstrument=instrumentsMap != null && instrumentsMap.get($INSTRUMENT.text) != null ? instrumentsMap.get($INSTRUMENT.text) : \"NO_INSTRIMENT\"))
            // AmFmCodeGenerator.g:62:9: ^( ID INSTRUMENT (nu+= note_unit )+ )
            {
            ID1=(CommonTree)match(input,ID,FOLLOW_ID_in_seed122); 

            match(input, Token.DOWN, null); 
            INSTRUMENT2=(CommonTree)match(input,INSTRUMENT,FOLLOW_INSTRUMENT_in_seed124); 
            // AmFmCodeGenerator.g:62:25: (nu+= note_unit )+
            int cnt2=0;
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==NOTEUNIT) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // AmFmCodeGenerator.g:62:26: nu+= note_unit
            	    {
            	    pushFollow(FOLLOW_note_unit_in_seed129);
            	    nu=note_unit();

            	    state._fsp--;

            	    if (list_nu==null) list_nu=new ArrayList();
            	    list_nu.add(nu.getTemplate());


            	    }
            	    break;

            	default :
            	    if ( cnt2 >= 1 ) break loop2;
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);


            match(input, Token.UP, null); 


            // TEMPLATE REWRITE
            // 63:9: -> seed_tpl(name=$ID.textnu=$nuinstrument=instrumentsMap != null && instrumentsMap.get($INSTRUMENT.text) != null ? instrumentsMap.get($INSTRUMENT.text) : \"NO_INSTRIMENT\")
            {
                retval.st = templateLib.getInstanceOf("seed_tpl",
              new STAttrMap().put("name", (ID1!=null?ID1.getText():null)).put("nu", list_nu).put("instrument", instrumentsMap != null && instrumentsMap.get((INSTRUMENT2!=null?INSTRUMENT2.getText():null)) != null ? instrumentsMap.get((INSTRUMENT2!=null?INSTRUMENT2.getText():null)) : "NO_INSTRIMENT"));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "seed"

    public static class note_unit_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "note_unit"
    // AmFmCodeGenerator.g:65:1: note_unit : ( ^( NOTEUNIT ^( NOTE n= note ) (d= duration (v= volume )? )? ) -> {%{\"\" + $n.st + (d != null ? \",\" + $d.st : \"\") + (v != null ? \",\" + $v.st : \"\") }} | ^( NOTEUNIT REST (d= duration )? ) -> {%{$REST.text + (d != null ? \",\" + $d.st : \"\")}});
    public final AmFmCodeGenerator.note_unit_return note_unit() throws RecognitionException {
        AmFmCodeGenerator.note_unit_return retval = new AmFmCodeGenerator.note_unit_return();
        retval.start = input.LT(1);

        CommonTree REST3=null;
        AmFmCodeGenerator.note_return n = null;

        AmFmCodeGenerator.duration_return d = null;

        AmFmCodeGenerator.volume_return v = null;


        try {
            // AmFmCodeGenerator.g:65:11: ( ^( NOTEUNIT ^( NOTE n= note ) (d= duration (v= volume )? )? ) -> {%{\"\" + $n.st + (d != null ? \",\" + $d.st : \"\") + (v != null ? \",\" + $v.st : \"\") }} | ^( NOTEUNIT REST (d= duration )? ) -> {%{$REST.text + (d != null ? \",\" + $d.st : \"\")}})
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==NOTEUNIT) ) {
                int LA6_1 = input.LA(2);

                if ( (LA6_1==DOWN) ) {
                    int LA6_2 = input.LA(3);

                    if ( (LA6_2==NOTE) ) {
                        alt6=1;
                    }
                    else if ( (LA6_2==REST) ) {
                        alt6=2;
                    }
                    else {
                        NoViableAltException nvae =
                            new NoViableAltException("", 6, 2, input);

                        throw nvae;
                    }
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 6, 1, input);

                    throw nvae;
                }
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;
            }
            switch (alt6) {
                case 1 :
                    // AmFmCodeGenerator.g:65:13: ^( NOTEUNIT ^( NOTE n= note ) (d= duration (v= volume )? )? )
                    {
                    match(input,NOTEUNIT,FOLLOW_NOTEUNIT_in_note_unit189); 

                    match(input, Token.DOWN, null); 
                    match(input,NOTE,FOLLOW_NOTE_in_note_unit192); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_note_in_note_unit196);
                    n=note();

                    state._fsp--;


                    match(input, Token.UP, null); 
                    // AmFmCodeGenerator.g:65:39: (d= duration (v= volume )? )?
                    int alt4=2;
                    int LA4_0 = input.LA(1);

                    if ( (LA4_0==FRACTION||LA4_0==ONE_TO_NINE||LA4_0==TEN_AND_UP) ) {
                        alt4=1;
                    }
                    switch (alt4) {
                        case 1 :
                            // AmFmCodeGenerator.g:65:40: d= duration (v= volume )?
                            {
                            pushFollow(FOLLOW_duration_in_note_unit202);
                            d=duration();

                            state._fsp--;

                            // AmFmCodeGenerator.g:65:51: (v= volume )?
                            int alt3=2;
                            int LA3_0 = input.LA(1);

                            if ( (LA3_0==VOLUME_LEVELS_MINUS_F||LA3_0==34) ) {
                                alt3=1;
                            }
                            switch (alt3) {
                                case 1 :
                                    // AmFmCodeGenerator.g:65:52: v= volume
                                    {
                                    pushFollow(FOLLOW_volume_in_note_unit207);
                                    v=volume();

                                    state._fsp--;


                                    }
                                    break;

                            }


                            }
                            break;

                    }


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 66:13: -> {%{\"\" + $n.st + (d != null ? \",\" + $d.st : \"\") + (v != null ? \",\" + $v.st : \"\") }}
                    {
                        retval.st = new StringTemplate(templateLib,"" + (n!=null?n.st:null) + (d != null ? "," + (d!=null?d.st:null) : "") + (v != null ? "," + (v!=null?v.st:null) : "") );
                    }


                    }
                    break;
                case 2 :
                    // AmFmCodeGenerator.g:67:13: ^( NOTEUNIT REST (d= duration )? )
                    {
                    match(input,NOTEUNIT,FOLLOW_NOTEUNIT_in_note_unit245); 

                    match(input, Token.DOWN, null); 
                    REST3=(CommonTree)match(input,REST,FOLLOW_REST_in_note_unit247); 
                    // AmFmCodeGenerator.g:67:29: (d= duration )?
                    int alt5=2;
                    int LA5_0 = input.LA(1);

                    if ( (LA5_0==FRACTION||LA5_0==ONE_TO_NINE||LA5_0==TEN_AND_UP) ) {
                        alt5=1;
                    }
                    switch (alt5) {
                        case 1 :
                            // AmFmCodeGenerator.g:67:30: d= duration
                            {
                            pushFollow(FOLLOW_duration_in_note_unit252);
                            d=duration();

                            state._fsp--;


                            }
                            break;

                    }


                    match(input, Token.UP, null); 


                    // TEMPLATE REWRITE
                    // 68:13: -> {%{$REST.text + (d != null ? \",\" + $d.st : \"\")}}
                    {
                        retval.st = new StringTemplate(templateLib,(REST3!=null?REST3.getText():null) + (d != null ? "," + (d!=null?d.st:null) : ""));
                    }


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "note_unit"

    public static class duration_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "duration"
    // AmFmCodeGenerator.g:70:1: duration : ( FRACTION -> {%{$text}} | number -> {%{$text}});
    public final AmFmCodeGenerator.duration_return duration() throws RecognitionException {
        AmFmCodeGenerator.duration_return retval = new AmFmCodeGenerator.duration_return();
        retval.start = input.LT(1);

        try {
            // AmFmCodeGenerator.g:70:9: ( FRACTION -> {%{$text}} | number -> {%{$text}})
            int alt7=2;
            int LA7_0 = input.LA(1);

            if ( (LA7_0==FRACTION) ) {
                alt7=1;
            }
            else if ( (LA7_0==ONE_TO_NINE||LA7_0==TEN_AND_UP) ) {
                alt7=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 7, 0, input);

                throw nvae;
            }
            switch (alt7) {
                case 1 :
                    // AmFmCodeGenerator.g:70:11: FRACTION
                    {
                    match(input,FRACTION,FOLLOW_FRACTION_in_duration289); 


                    // TEMPLATE REWRITE
                    // 70:20: -> {%{$text}}
                    {
                        retval.st = new StringTemplate(templateLib,input.getTokenStream().toString(
                      input.getTreeAdaptor().getTokenStartIndex(retval.start),
                      input.getTreeAdaptor().getTokenStopIndex(retval.start)));
                    }


                    }
                    break;
                case 2 :
                    // AmFmCodeGenerator.g:71:11: number
                    {
                    pushFollow(FOLLOW_number_in_duration308);
                    number();

                    state._fsp--;



                    // TEMPLATE REWRITE
                    // 71:18: -> {%{$text}}
                    {
                        retval.st = new StringTemplate(templateLib,input.getTokenStream().toString(
                      input.getTreeAdaptor().getTokenStartIndex(retval.start),
                      input.getTreeAdaptor().getTokenStopIndex(retval.start)));
                    }


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "duration"

    public static class volume_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "volume"
    // AmFmCodeGenerator.g:73:1: volume : ( VOLUME_LEVELS_MINUS_F -> {%{$text}} | 'F' -> {%{$text}});
    public final AmFmCodeGenerator.volume_return volume() throws RecognitionException {
        AmFmCodeGenerator.volume_return retval = new AmFmCodeGenerator.volume_return();
        retval.start = input.LT(1);

        try {
            // AmFmCodeGenerator.g:73:9: ( VOLUME_LEVELS_MINUS_F -> {%{$text}} | 'F' -> {%{$text}})
            int alt8=2;
            int LA8_0 = input.LA(1);

            if ( (LA8_0==VOLUME_LEVELS_MINUS_F) ) {
                alt8=1;
            }
            else if ( (LA8_0==34) ) {
                alt8=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 8, 0, input);

                throw nvae;
            }
            switch (alt8) {
                case 1 :
                    // AmFmCodeGenerator.g:73:11: VOLUME_LEVELS_MINUS_F
                    {
                    match(input,VOLUME_LEVELS_MINUS_F,FOLLOW_VOLUME_LEVELS_MINUS_F_in_volume332); 


                    // TEMPLATE REWRITE
                    // 73:33: -> {%{$text}}
                    {
                        retval.st = new StringTemplate(templateLib,input.getTokenStream().toString(
                      input.getTreeAdaptor().getTokenStartIndex(retval.start),
                      input.getTreeAdaptor().getTokenStopIndex(retval.start)));
                    }


                    }
                    break;
                case 2 :
                    // AmFmCodeGenerator.g:74:11: 'F'
                    {
                    match(input,34,FOLLOW_34_in_volume348); 


                    // TEMPLATE REWRITE
                    // 74:15: -> {%{$text}}
                    {
                        retval.st = new StringTemplate(templateLib,input.getTokenStream().toString(
                      input.getTreeAdaptor().getTokenStartIndex(retval.start),
                      input.getTreeAdaptor().getTokenStopIndex(retval.start)));
                    }


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "volume"

    public static class note_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "note"
    // AmFmCodeGenerator.g:76:1: note : nl= note_letter (o= octave )? -> {%{\"\" + $nl.st + (o != null ? $o.st : DEFAULT_OCTAVE)}};
    public final AmFmCodeGenerator.note_return note() throws RecognitionException {
        AmFmCodeGenerator.note_return retval = new AmFmCodeGenerator.note_return();
        retval.start = input.LT(1);

        AmFmCodeGenerator.note_letter_return nl = null;

        AmFmCodeGenerator.octave_return o = null;


        try {
            // AmFmCodeGenerator.g:76:6: (nl= note_letter (o= octave )? -> {%{\"\" + $nl.st + (o != null ? $o.st : DEFAULT_OCTAVE)}})
            // AmFmCodeGenerator.g:76:9: nl= note_letter (o= octave )?
            {
            pushFollow(FOLLOW_note_letter_in_note371);
            nl=note_letter();

            state._fsp--;

            // AmFmCodeGenerator.g:76:25: (o= octave )?
            int alt9=2;
            int LA9_0 = input.LA(1);

            if ( (LA9_0==ONE_TO_NINE) ) {
                alt9=1;
            }
            switch (alt9) {
                case 1 :
                    // AmFmCodeGenerator.g:76:25: o= octave
                    {
                    pushFollow(FOLLOW_octave_in_note375);
                    o=octave();

                    state._fsp--;


                    }
                    break;

            }



            // TEMPLATE REWRITE
            // 76:34: -> {%{\"\" + $nl.st + (o != null ? $o.st : DEFAULT_OCTAVE)}}
            {
                retval.st = new StringTemplate(templateLib,"" + (nl!=null?nl.st:null) + (o != null ? (o!=null?o.st:null) : DEFAULT_OCTAVE));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "note"

    public static class note_letter_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "note_letter"
    // AmFmCodeGenerator.g:77:1: note_letter : ( NOTELETTERS_WITH_ACCIDENTAL_MINUS_F -> {%{$NOTELETTERS_WITH_ACCIDENTAL_MINUS_F.text}} | 'F' ( ACCIDENTAL )? -> {%{\"F\" + ($ACCIDENTAL.text != null ? $ACCIDENTAL.text : \"\")}});
    public final AmFmCodeGenerator.note_letter_return note_letter() throws RecognitionException {
        AmFmCodeGenerator.note_letter_return retval = new AmFmCodeGenerator.note_letter_return();
        retval.start = input.LT(1);

        CommonTree NOTELETTERS_WITH_ACCIDENTAL_MINUS_F4=null;
        CommonTree ACCIDENTAL5=null;

        try {
            // AmFmCodeGenerator.g:77:12: ( NOTELETTERS_WITH_ACCIDENTAL_MINUS_F -> {%{$NOTELETTERS_WITH_ACCIDENTAL_MINUS_F.text}} | 'F' ( ACCIDENTAL )? -> {%{\"F\" + ($ACCIDENTAL.text != null ? $ACCIDENTAL.text : \"\")}})
            int alt11=2;
            int LA11_0 = input.LA(1);

            if ( (LA11_0==NOTELETTERS_WITH_ACCIDENTAL_MINUS_F) ) {
                alt11=1;
            }
            else if ( (LA11_0==34) ) {
                alt11=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 11, 0, input);

                throw nvae;
            }
            switch (alt11) {
                case 1 :
                    // AmFmCodeGenerator.g:77:14: NOTELETTERS_WITH_ACCIDENTAL_MINUS_F
                    {
                    NOTELETTERS_WITH_ACCIDENTAL_MINUS_F4=(CommonTree)match(input,NOTELETTERS_WITH_ACCIDENTAL_MINUS_F,FOLLOW_NOTELETTERS_WITH_ACCIDENTAL_MINUS_F_in_note_letter387); 


                    // TEMPLATE REWRITE
                    // 77:51: -> {%{$NOTELETTERS_WITH_ACCIDENTAL_MINUS_F.text}}
                    {
                        retval.st = new StringTemplate(templateLib,(NOTELETTERS_WITH_ACCIDENTAL_MINUS_F4!=null?NOTELETTERS_WITH_ACCIDENTAL_MINUS_F4.getText():null));
                    }


                    }
                    break;
                case 2 :
                    // AmFmCodeGenerator.g:78:14: 'F' ( ACCIDENTAL )?
                    {
                    match(input,34,FOLLOW_34_in_note_letter407); 
                    // AmFmCodeGenerator.g:78:17: ( ACCIDENTAL )?
                    int alt10=2;
                    int LA10_0 = input.LA(1);

                    if ( (LA10_0==ACCIDENTAL) ) {
                        alt10=1;
                    }
                    switch (alt10) {
                        case 1 :
                            // AmFmCodeGenerator.g:78:17: ACCIDENTAL
                            {
                            ACCIDENTAL5=(CommonTree)match(input,ACCIDENTAL,FOLLOW_ACCIDENTAL_in_note_letter408); 

                            }
                            break;

                    }



                    // TEMPLATE REWRITE
                    // 78:29: -> {%{\"F\" + ($ACCIDENTAL.text != null ? $ACCIDENTAL.text : \"\")}}
                    {
                        retval.st = new StringTemplate(templateLib,"F" + ((ACCIDENTAL5!=null?ACCIDENTAL5.getText():null) != null ? (ACCIDENTAL5!=null?ACCIDENTAL5.getText():null) : ""));
                    }


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "note_letter"

    public static class octave_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "octave"
    // AmFmCodeGenerator.g:80:1: octave : ONE_TO_NINE -> {%{$text}};
    public final AmFmCodeGenerator.octave_return octave() throws RecognitionException {
        AmFmCodeGenerator.octave_return retval = new AmFmCodeGenerator.octave_return();
        retval.start = input.LT(1);

        try {
            // AmFmCodeGenerator.g:80:7: ( ONE_TO_NINE -> {%{$text}})
            // AmFmCodeGenerator.g:80:9: ONE_TO_NINE
            {
            match(input,ONE_TO_NINE,FOLLOW_ONE_TO_NINE_in_octave431); 


            // TEMPLATE REWRITE
            // 80:21: -> {%{$text}}
            {
                retval.st = new StringTemplate(templateLib,input.getTokenStream().toString(
              input.getTreeAdaptor().getTokenStartIndex(retval.start),
              input.getTreeAdaptor().getTokenStopIndex(retval.start)));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "octave"

    public static class start_func_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "start_func"
    // AmFmCodeGenerator.g:83:1: start_func : ^( START (f+= function )* ) -> start_function_tpl(functions=$f);
    public final AmFmCodeGenerator.start_func_return start_func() throws RecognitionException {
        AmFmCodeGenerator.start_func_return retval = new AmFmCodeGenerator.start_func_return();
        retval.start = input.LT(1);

        List list_f=null;
        AmFmCodeGenerator.function_return f = null;
         f = null;
        try {
            // AmFmCodeGenerator.g:83:11: ( ^( START (f+= function )* ) -> start_function_tpl(functions=$f))
            // AmFmCodeGenerator.g:83:14: ^( START (f+= function )* )
            {
            match(input,START,FOLLOW_START_in_start_func445); 

            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // AmFmCodeGenerator.g:83:22: (f+= function )*
                loop12:
                do {
                    int alt12=2;
                    int LA12_0 = input.LA(1);

                    if ( ((LA12_0>=PLAY && LA12_0<=SS_ALL)) ) {
                        alt12=1;
                    }


                    switch (alt12) {
                	case 1 :
                	    // AmFmCodeGenerator.g:83:23: f+= function
                	    {
                	    pushFollow(FOLLOW_function_in_start_func450);
                	    f=function();

                	    state._fsp--;

                	    if (list_f==null) list_f=new ArrayList();
                	    list_f.add(f.getTemplate());


                	    }
                	    break;

                	default :
                	    break loop12;
                    }
                } while (true);


                match(input, Token.UP, null); 
            }


            // TEMPLATE REWRITE
            // 84:14: -> start_function_tpl(functions=$f)
            {
                retval.st = templateLib.getInstanceOf("start_function_tpl",
              new STAttrMap().put("functions", list_f));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "start_func"

    public static class function_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "function"
    // AmFmCodeGenerator.g:85:1: function : (p= play -> function_call_tpl(all_args=$p.st) | ss_f= ss_func -> function_call_tpl(all_args=$ss_f.st));
    public final AmFmCodeGenerator.function_return function() throws RecognitionException {
        AmFmCodeGenerator.function_return retval = new AmFmCodeGenerator.function_return();
        retval.start = input.LT(1);

        AmFmCodeGenerator.play_return p = null;

        AmFmCodeGenerator.ss_func_return ss_f = null;


        try {
            // AmFmCodeGenerator.g:85:9: (p= play -> function_call_tpl(all_args=$p.st) | ss_f= ss_func -> function_call_tpl(all_args=$ss_f.st))
            int alt13=2;
            int LA13_0 = input.LA(1);

            if ( (LA13_0==PLAY) ) {
                alt13=1;
            }
            else if ( ((LA13_0>=SS_PITCH && LA13_0<=SS_ALL)) ) {
                alt13=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 13, 0, input);

                throw nvae;
            }
            switch (alt13) {
                case 1 :
                    // AmFmCodeGenerator.g:85:11: p= play
                    {
                    pushFollow(FOLLOW_play_in_function483);
                    p=play();

                    state._fsp--;



                    // TEMPLATE REWRITE
                    // 85:18: -> function_call_tpl(all_args=$p.st)
                    {
                        retval.st = templateLib.getInstanceOf("function_call_tpl",
                      new STAttrMap().put("all_args", (p!=null?p.st:null)));
                    }


                    }
                    break;
                case 2 :
                    // AmFmCodeGenerator.g:86:11: ss_f= ss_func
                    {
                    pushFollow(FOLLOW_ss_func_in_function506);
                    ss_f=ss_func();

                    state._fsp--;



                    // TEMPLATE REWRITE
                    // 86:24: -> function_call_tpl(all_args=$ss_f.st)
                    {
                        retval.st = templateLib.getInstanceOf("function_call_tpl",
                      new STAttrMap().put("all_args", (ss_f!=null?ss_f.st:null)));
                    }


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "function"

    public static class play_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "play"
    // AmFmCodeGenerator.g:88:1: play : ^( PLAY fp= func_params ) -> {%{$fp.st + \", false, false, false, false\"}};
    public final AmFmCodeGenerator.play_return play() throws RecognitionException {
        AmFmCodeGenerator.play_return retval = new AmFmCodeGenerator.play_return();
        retval.start = input.LT(1);

        AmFmCodeGenerator.func_params_return fp = null;


        try {
            // AmFmCodeGenerator.g:88:5: ( ^( PLAY fp= func_params ) -> {%{$fp.st + \", false, false, false, false\"}})
            // AmFmCodeGenerator.g:88:7: ^( PLAY fp= func_params )
            {
            match(input,PLAY,FOLLOW_PLAY_in_play532); 

            match(input, Token.DOWN, null); 
            pushFollow(FOLLOW_func_params_in_play536);
            fp=func_params();

            state._fsp--;


            match(input, Token.UP, null); 


            // TEMPLATE REWRITE
            // 88:30: -> {%{$fp.st + \", false, false, false, false\"}}
            {
                retval.st = new StringTemplate(templateLib,(fp!=null?fp.st:null) + ", false, false, false, false");
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "play"

    public static class ss_func_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "ss_func"
    // AmFmCodeGenerator.g:89:1: ss_func : ^(fn= ss_func_name sfp= ss_func_params ) -> {%{$sfp.st + \", \" + $fn.st}};
    public final AmFmCodeGenerator.ss_func_return ss_func() throws RecognitionException {
        AmFmCodeGenerator.ss_func_return retval = new AmFmCodeGenerator.ss_func_return();
        retval.start = input.LT(1);

        AmFmCodeGenerator.ss_func_name_return fn = null;

        AmFmCodeGenerator.ss_func_params_return sfp = null;


        try {
            // AmFmCodeGenerator.g:89:8: ( ^(fn= ss_func_name sfp= ss_func_params ) -> {%{$sfp.st + \", \" + $fn.st}})
            // AmFmCodeGenerator.g:89:10: ^(fn= ss_func_name sfp= ss_func_params )
            {
            pushFollow(FOLLOW_ss_func_name_in_ss_func550);
            fn=ss_func_name();

            state._fsp--;


            match(input, Token.DOWN, null); 
            pushFollow(FOLLOW_ss_func_params_in_ss_func554);
            sfp=ss_func_params();

            state._fsp--;


            match(input, Token.UP, null); 


            // TEMPLATE REWRITE
            // 89:48: -> {%{$sfp.st + \", \" + $fn.st}}
            {
                retval.st = new StringTemplate(templateLib,(sfp!=null?sfp.st:null) + ", " + (fn!=null?fn.st:null));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ss_func"

    public static class ss_func_name_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "ss_func_name"
    // AmFmCodeGenerator.g:90:1: ss_func_name : ( SS_PITCH -> {%{\"true, false, false\"}} | SS_VOLUME -> {%{\"false, false, true\"}} | SS_RHYTHM -> {%{\"false, true, false\"}} | SS_PITCH_VOLUME -> {%{\"true, false, true\"}} | SS_PITCH_RHYTHM -> {%{\"true, true, false\"}} | SS_RHYTHM_VOLUME -> {%{\"false, true, true\"}} | SS_ALL -> {%{\"true, true, true\"}});
    public final AmFmCodeGenerator.ss_func_name_return ss_func_name() throws RecognitionException {
        AmFmCodeGenerator.ss_func_name_return retval = new AmFmCodeGenerator.ss_func_name_return();
        retval.start = input.LT(1);

        try {
            // AmFmCodeGenerator.g:90:13: ( SS_PITCH -> {%{\"true, false, false\"}} | SS_VOLUME -> {%{\"false, false, true\"}} | SS_RHYTHM -> {%{\"false, true, false\"}} | SS_PITCH_VOLUME -> {%{\"true, false, true\"}} | SS_PITCH_RHYTHM -> {%{\"true, true, false\"}} | SS_RHYTHM_VOLUME -> {%{\"false, true, true\"}} | SS_ALL -> {%{\"true, true, true\"}})
            int alt14=7;
            switch ( input.LA(1) ) {
            case SS_PITCH:
                {
                alt14=1;
                }
                break;
            case SS_VOLUME:
                {
                alt14=2;
                }
                break;
            case SS_RHYTHM:
                {
                alt14=3;
                }
                break;
            case SS_PITCH_VOLUME:
                {
                alt14=4;
                }
                break;
            case SS_PITCH_RHYTHM:
                {
                alt14=5;
                }
                break;
            case SS_RHYTHM_VOLUME:
                {
                alt14=6;
                }
                break;
            case SS_ALL:
                {
                alt14=7;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 14, 0, input);

                throw nvae;
            }

            switch (alt14) {
                case 1 :
                    // AmFmCodeGenerator.g:90:15: SS_PITCH
                    {
                    match(input,SS_PITCH,FOLLOW_SS_PITCH_in_ss_func_name565); 


                    // TEMPLATE REWRITE
                    // 90:24: -> {%{\"true, false, false\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"true, false, false");
                    }


                    }
                    break;
                case 2 :
                    // AmFmCodeGenerator.g:91:15: SS_VOLUME
                    {
                    match(input,SS_VOLUME,FOLLOW_SS_VOLUME_in_ss_func_name585); 


                    // TEMPLATE REWRITE
                    // 91:25: -> {%{\"false, false, true\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"false, false, true");
                    }


                    }
                    break;
                case 3 :
                    // AmFmCodeGenerator.g:92:15: SS_RHYTHM
                    {
                    match(input,SS_RHYTHM,FOLLOW_SS_RHYTHM_in_ss_func_name605); 


                    // TEMPLATE REWRITE
                    // 92:25: -> {%{\"false, true, false\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"false, true, false");
                    }


                    }
                    break;
                case 4 :
                    // AmFmCodeGenerator.g:93:15: SS_PITCH_VOLUME
                    {
                    match(input,SS_PITCH_VOLUME,FOLLOW_SS_PITCH_VOLUME_in_ss_func_name625); 


                    // TEMPLATE REWRITE
                    // 93:31: -> {%{\"true, false, true\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"true, false, true");
                    }


                    }
                    break;
                case 5 :
                    // AmFmCodeGenerator.g:94:15: SS_PITCH_RHYTHM
                    {
                    match(input,SS_PITCH_RHYTHM,FOLLOW_SS_PITCH_RHYTHM_in_ss_func_name645); 


                    // TEMPLATE REWRITE
                    // 94:31: -> {%{\"true, true, false\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"true, true, false");
                    }


                    }
                    break;
                case 6 :
                    // AmFmCodeGenerator.g:95:15: SS_RHYTHM_VOLUME
                    {
                    match(input,SS_RHYTHM_VOLUME,FOLLOW_SS_RHYTHM_VOLUME_in_ss_func_name665); 


                    // TEMPLATE REWRITE
                    // 95:32: -> {%{\"false, true, true\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"false, true, true");
                    }


                    }
                    break;
                case 7 :
                    // AmFmCodeGenerator.g:96:15: SS_ALL
                    {
                    match(input,SS_ALL,FOLLOW_SS_ALL_in_ss_func_name686); 


                    // TEMPLATE REWRITE
                    // 96:22: -> {%{\"true, true, true\"}}
                    {
                        retval.st = new StringTemplate(templateLib,"true, true, true");
                    }


                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ss_func_name"

    public static class ss_func_params_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "ss_func_params"
    // AmFmCodeGenerator.g:98:1: ss_func_params : fp= func_params BOOLEAN -> {%{\"\" + $fp.st + \", \" + (\"TRUE\".equals($BOOLEAN.text) ? \"true\" : \"false\" ) }};
    public final AmFmCodeGenerator.ss_func_params_return ss_func_params() throws RecognitionException {
        AmFmCodeGenerator.ss_func_params_return retval = new AmFmCodeGenerator.ss_func_params_return();
        retval.start = input.LT(1);

        CommonTree BOOLEAN6=null;
        AmFmCodeGenerator.func_params_return fp = null;


        try {
            // AmFmCodeGenerator.g:98:15: (fp= func_params BOOLEAN -> {%{\"\" + $fp.st + \", \" + (\"TRUE\".equals($BOOLEAN.text) ? \"true\" : \"false\" ) }})
            // AmFmCodeGenerator.g:98:17: fp= func_params BOOLEAN
            {
            pushFollow(FOLLOW_func_params_in_ss_func_params711);
            fp=func_params();

            state._fsp--;

            BOOLEAN6=(CommonTree)match(input,BOOLEAN,FOLLOW_BOOLEAN_in_ss_func_params713); 


            // TEMPLATE REWRITE
            // 98:40: -> {%{\"\" + $fp.st + \", \" + (\"TRUE\".equals($BOOLEAN.text) ? \"true\" : \"false\" ) }}
            {
                retval.st = new StringTemplate(templateLib,"" + (fp!=null?fp.st:null) + ", " + ("TRUE".equals((BOOLEAN6!=null?BOOLEAN6.getText():null)) ? "true" : "false" ) );
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ss_func_params"

    public static class func_params_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "func_params"
    // AmFmCodeGenerator.g:99:1: func_params : ID sb= start_bar nb= num_of_bars -> {%{\"\\\"\" + $ID.text + \"\\\", \" + $sb.text + \", \" + $nb.text}};
    public final AmFmCodeGenerator.func_params_return func_params() throws RecognitionException {
        AmFmCodeGenerator.func_params_return retval = new AmFmCodeGenerator.func_params_return();
        retval.start = input.LT(1);

        CommonTree ID7=null;
        AmFmCodeGenerator.start_bar_return sb = null;

        AmFmCodeGenerator.num_of_bars_return nb = null;


        try {
            // AmFmCodeGenerator.g:99:12: ( ID sb= start_bar nb= num_of_bars -> {%{\"\\\"\" + $ID.text + \"\\\", \" + $sb.text + \", \" + $nb.text}})
            // AmFmCodeGenerator.g:99:14: ID sb= start_bar nb= num_of_bars
            {
            ID7=(CommonTree)match(input,ID,FOLLOW_ID_in_func_params723); 
            pushFollow(FOLLOW_start_bar_in_func_params727);
            sb=start_bar();

            state._fsp--;

            pushFollow(FOLLOW_num_of_bars_in_func_params731);
            nb=num_of_bars();

            state._fsp--;



            // TEMPLATE REWRITE
            // 99:45: -> {%{\"\\\"\" + $ID.text + \"\\\", \" + $sb.text + \", \" + $nb.text}}
            {
                retval.st = new StringTemplate(templateLib,"\"" + (ID7!=null?ID7.getText():null) +  "\", " + (sb!=null?(input.getTokenStream().toString(
              input.getTreeAdaptor().getTokenStartIndex(sb.start),
              input.getTreeAdaptor().getTokenStopIndex(sb.start))):null) + ", " + (nb!=null?(input.getTokenStream().toString(
              input.getTreeAdaptor().getTokenStartIndex(nb.start),
              input.getTreeAdaptor().getTokenStopIndex(nb.start))):null));
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "func_params"

    public static class start_bar_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "start_bar"
    // AmFmCodeGenerator.g:100:1: start_bar : number ;
    public final AmFmCodeGenerator.start_bar_return start_bar() throws RecognitionException {
        AmFmCodeGenerator.start_bar_return retval = new AmFmCodeGenerator.start_bar_return();
        retval.start = input.LT(1);

        try {
            // AmFmCodeGenerator.g:100:10: ( number )
            // AmFmCodeGenerator.g:100:12: number
            {
            pushFollow(FOLLOW_number_in_start_bar742);
            number();

            state._fsp--;


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "start_bar"

    public static class num_of_bars_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "num_of_bars"
    // AmFmCodeGenerator.g:101:1: num_of_bars : number ;
    public final AmFmCodeGenerator.num_of_bars_return num_of_bars() throws RecognitionException {
        AmFmCodeGenerator.num_of_bars_return retval = new AmFmCodeGenerator.num_of_bars_return();
        retval.start = input.LT(1);

        try {
            // AmFmCodeGenerator.g:101:12: ( number )
            // AmFmCodeGenerator.g:101:14: number
            {
            pushFollow(FOLLOW_number_in_num_of_bars749);
            number();

            state._fsp--;


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "num_of_bars"

    public static class number_return extends TreeRuleReturnScope {
        public StringTemplate st;
        public Object getTemplate() { return st; }
        public String toString() { return st==null?null:st.toString(); }
    };

    // $ANTLR start "number"
    // AmFmCodeGenerator.g:102:1: number : ( ONE_TO_NINE | TEN_AND_UP );
    public final AmFmCodeGenerator.number_return number() throws RecognitionException {
        AmFmCodeGenerator.number_return retval = new AmFmCodeGenerator.number_return();
        retval.start = input.LT(1);

        try {
            // AmFmCodeGenerator.g:102:9: ( ONE_TO_NINE | TEN_AND_UP )
            // AmFmCodeGenerator.g:
            {
            if ( input.LA(1)==ONE_TO_NINE||input.LA(1)==TEN_AND_UP ) {
                input.consume();
                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "number"

    // Delegated rules


 

    public static final BitSet FOLLOW_PROGRAM_in_program46 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_seed_in_program51 = new BitSet(new long[]{0x0000000000010100L});
    public static final BitSet FOLLOW_start_func_in_program58 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_ID_in_seed122 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_INSTRUMENT_in_seed124 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_note_unit_in_seed129 = new BitSet(new long[]{0x0000000000000048L});
    public static final BitSet FOLLOW_NOTEUNIT_in_note_unit189 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_NOTE_in_note_unit192 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_note_in_note_unit196 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_duration_in_note_unit202 = new BitSet(new long[]{0x0000000400001008L});
    public static final BitSet FOLLOW_volume_in_note_unit207 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_NOTEUNIT_in_note_unit245 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_REST_in_note_unit247 = new BitSet(new long[]{0x0000000004008808L});
    public static final BitSet FOLLOW_duration_in_note_unit252 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_FRACTION_in_duration289 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_number_in_duration308 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_VOLUME_LEVELS_MINUS_F_in_volume332 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_34_in_volume348 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_note_letter_in_note371 = new BitSet(new long[]{0x0000000000008002L});
    public static final BitSet FOLLOW_octave_in_note375 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_NOTELETTERS_WITH_ACCIDENTAL_MINUS_F_in_note_letter387 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_34_in_note_letter407 = new BitSet(new long[]{0x0000000000004002L});
    public static final BitSet FOLLOW_ACCIDENTAL_in_note_letter408 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ONE_TO_NINE_in_octave431 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_START_in_start_func445 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_function_in_start_func450 = new BitSet(new long[]{0x0000000001FE0008L});
    public static final BitSet FOLLOW_play_in_function483 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ss_func_in_function506 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_PLAY_in_play532 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_func_params_in_play536 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_ss_func_name_in_ss_func550 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ss_func_params_in_ss_func554 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_SS_PITCH_in_ss_func_name565 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SS_VOLUME_in_ss_func_name585 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SS_RHYTHM_in_ss_func_name605 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SS_PITCH_VOLUME_in_ss_func_name625 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SS_PITCH_RHYTHM_in_ss_func_name645 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SS_RHYTHM_VOLUME_in_ss_func_name665 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_SS_ALL_in_ss_func_name686 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_func_params_in_ss_func_params711 = new BitSet(new long[]{0x0000000002000000L});
    public static final BitSet FOLLOW_BOOLEAN_in_ss_func_params713 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_func_params723 = new BitSet(new long[]{0x0000000004008800L});
    public static final BitSet FOLLOW_start_bar_in_func_params727 = new BitSet(new long[]{0x0000000004008800L});
    public static final BitSet FOLLOW_num_of_bars_in_func_params731 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_number_in_start_bar742 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_number_in_num_of_bars749 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_number0 = new BitSet(new long[]{0x0000000000000002L});

}